package com.vpx.server.framework.utils;

import java.util.Date;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/**
 * @author xx
 * @title: vpx
 * @module 
 * @description: 
 * @date 
 */
public class TaskSendLock {
    private static final Map<String, String> TASK_STATUS_MAP = new ConcurrentHashMap<>();

    public static int isOver(String groupId, int timeOut) {
        long begin = System.currentTimeMillis();;

        while (true) {
            if ("OVER".equals(TASK_STATUS_MAP.get(groupId))) {
                TASK_STATUS_MAP.remove(groupId);
                return 1;
            }
            try {
                Thread.sleep(500);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            long current = System.currentTimeMillis();
            if (current - begin >= timeOut) {
                return -1;
            }
        }
    }

    public static void over(String groupId) {
        try {
            TASK_STATUS_MAP.put(groupId, "OVER");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
